package com.itheima.reggie.handler;

import com.itheima.reggie.commom.CustomException;
import com.itheima.reggie.commom.ResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Sea
 * @date 2023/3/8 16:52
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    //预期异常处理方法
    @ExceptionHandler(CustomException.class)
    public ResultInfo exceptionHandler(CustomException customException) {
        log.error(customException.getMessage());
        return ResultInfo.error(customException.getMessage());
    }

    //非预期异常处理方法
    @ExceptionHandler(Exception.class)
    public ResultInfo exceptionHandler(Exception exception) {
        log.error(exception.getMessage());
        return ResultInfo.error("对不起，网络问题，请稍后再试");

    }
}

